package com.mm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
//import org.springframework.retry.annotation.EnableRetry;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication(
    //SpringBoot启动会自动注入数据源和配置jpa,这里排除掉
    exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}
)
//将服务注册到注册管理中心
@EnableDiscoveryClient
//@EnableRetry    //开启ribbon调用时的重试机制
public class RibbonApplication {
    @Bean
    @LoadBalanced   //开启客户端负载均衡
    RestTemplate restTemplate(Environment environment){
        return new RestTemplate();
//        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
//        int ribbonReadTimeout = environment.getProperty("ribbon.ReadTimeout", int.class, 1000);
//        int ribbonConnectTimeout = environment.getProperty("ribbon.ConnectTimeout", int.class, 1000);
//        httpRequestFactory.setReadTimeout(ribbonReadTimeout );
//        httpRequestFactory.setConnectTimeout(ribbonConnectTimeout);
//        return new RestTemplate(httpRequestFactory);
    }
    public static void main(String[] args) {
        SpringApplication.run(RibbonApplication.class, args);
    }
}
